<?php


namespace App\Models;


use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Drivers extends Model
{

    use Common, SoftDeletes;

    protected $table = 'drivers';

    protected $hidden = ['updated_at', 'deleted_at'];

    protected $casts = [
        'identity_photo' => 'array',
        'work_scope' => 'array',
        'licence_photo' => 'array'
    ];
    protected $fillable = [
        'phone','user_id','real_name','company_id','status'
    ];

    /**
     * 所属公司
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     * @Author 姿势就是力量
     */
    public function company()
    {
        return $this->belongsTo(Company::class, 'company_id', 'id');
    }



//    public function licence()
//    {
//        return $this->belongsTo(Licence::class, 'license_id', 'id');
//    }

    /**
     * 驾照类型
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     * @Author 姿势就是力量
     */

//    public function licence()
//    {
//        return $this->hasOne(Licence::class, 'license_id', 'id');
//    }

    /**
     * 司机拥有车辆
     * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
     * @Author 姿势就是力量
     */
    public function car()
    {
        return $this->hasManyThrough(
            Car::class,
            DriverCar::class,
            'driver_id',
            'id',

            'id',
            'car_id');
    }



    /**
     * 接单城市
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     * @Author 姿势就是力量
     */

    public function city()
    {
        return $this->belongsTo(Region::class, 'city', 'id');
    }


    /**
     * 头像
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     * @Author 姿势就是力量
     */
    public function head()
    {
        return $this->hasOne(UploadFile::class, 'id', 'head_image')->select(['id', 'file_url', 'file_name']);
    }


    /**
     * 所属用户
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     * @Author 姿势就是力量
     */
    public function user()
    {
        return $this->hasOne(User::class, 'id', 'user_id');
    }


    /**
     * 审核人
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     * @Author 姿势就是力量
     */
    public function auditor()
    {
        return $this->belongsTo(Management::class, 'auditor_id', 'id');
    }


    /**
     * 评论
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     * @Author 姿势就是力量
     */
    public function comment()
    {
        return $this->hasMany(Comment::class, 'driver_id', 'id');
    }


    /**
     * 提现账号
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     * @Author 姿势就是力量
     */

    public function wallet()
    {
        return $this->hasMany(DriverWithdrawWallet::class, 'driver_id', 'id');
    }

    /**
     * 代驾
     */
    public function driver_others()
    {
        return $this->hasOne(DriverOthers::class,'driver_id','id');
    }
}
